package com.tc.vms.producer;

import com.tc.vms.metric.VmsMetricsGroup;
import com.yammer.metrics.core.Meter;
import com.yammer.metrics.core.Timer;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * Created by yonghua.zhang on 2016/2/1.
 */
public class VmsProducerMetrics extends VmsMetricsGroup {
    private final String metricsId;
    private final Meter messageSuccessRate;
    private final Meter messageFailureRate;
    private final Meter byteRate;
    private final Timer sendCostRate;

    public VmsProducerMetrics(String metricsId) {
        this.metricsId = metricsId;
        Map<String, String> tags = new HashMap<String, String>(1);
        tags.put("client.id", metricsId);
        this.messageSuccessRate = newMeter("SuccessMessagePerSec", "messages", TimeUnit.SECONDS, tags);
        this.messageFailureRate = newMeter("FailureMessagePerSec", "messages", TimeUnit.SECONDS, tags);
        this.byteRate = newMeter("BytesPerSec", "bytes", TimeUnit.SECONDS, tags);
        this.sendCostRate = newTimer("ProducerSendRateAndTimeMs", TimeUnit.MILLISECONDS, TimeUnit.SECONDS, tags);
    }

    public String getMetricsId() {
        return metricsId;
    }

    public Meter messageSuccessRate() {
        return messageSuccessRate;
    }

    public Meter messageFailureRate() {
        return messageFailureRate;
    }

    public Meter byteRate() {
        return byteRate;
    }

    public Timer sendCostRate() {
        return sendCostRate;
    }
}
